<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .heart-container {
            position: relative;
            width: 20px;
            height: 30px;
            margin: 50px auto;
            cursor: pointer;
        }

        .heart {
            position: absolute;
            bottom: 0;
            width: 20px;
            height: 18px;
            transition: transform 0.2s;
        }

        .heart:before,
        .heart:after {
            position: absolute;
            content: "";
            left: 10px;
            top: 0;
            width: 10px;
            height: 16px;
            background: red;
            border-radius: 10px 10px 0 0;
            transform: rotate(-45deg);
            transform-origin: 0 100%;
        }

        .heart:after {
            left: 0;
            transform: rotate(45deg);
            transform-origin: 100% 100%;
        }

        .counter {
            position: absolute;
            top: -20px;
            width: 100%;
            text-align: center;
            font-size: 14px;
            font-weight: bold;
        }

        .heart-container:active .heart {
            transform: scale(0.85);
        }

        .float-number {
            position: absolute;
            font-size: 12px;
            color: red;
            font-weight: bold;
            opacity: 0;
            transition: all 0.5s ease-out;
        }

        @keyframes floatUp {
            0% {
                transform: translateY(0);
                opacity: 1;
            }

            100% {
                transform: translateY(-30px);
                opacity: 0;
            }
        }
    </style>
</head>

<body>
    <div class="heart-container" onclick="incrementCounter(event)">
        <div class="counter">0</div>
        <div class="heart"></div>
    </div>


    <script>
        let count = 0;
        function incrementCounter(event) {
            count++;
            // document.querySelector('.counter').textContent = count;

            const floatNumber = document.createElement('div');
            floatNumber.className = 'float-number';
            floatNumber.textContent = '+1';
            floatNumber.style.left = (event.clientX - 5) + 'px';
            floatNumber.style.top = (event.clientY - 10) + 'px';
            document.body.appendChild(floatNumber);

            setTimeout(() => {
                floatNumber.style.animation = 'floatUp 0.5s ease-out';
            }, 50);

            setTimeout(() => {
                document.body.removeChild(floatNumber);
            }, 550);
        }
    </script>
</body>

</html>